package com.yuexun.beilunpatient.ui.satisfaction.presenter.impl;

import com.yuexun.beilunpatient.base.BaseEntity;
import com.yuexun.beilunpatient.ui.satisfaction.bean.StartSatisfactionBean;
import com.yuexun.beilunpatient.ui.satisfaction.bean.TemplateBean;
import com.yuexun.beilunpatient.ui.satisfaction.bean.TemplateTypeBean;
import com.yuexun.beilunpatient.ui.satisfaction.model.ISatisfactionModel;
import com.yuexun.beilunpatient.ui.satisfaction.presenter.ITemplatePresenter;
import com.yuexun.beilunpatient.ui.satisfaction.ui.view.IStartSatisfactionView;
import com.yuexun.beilunpatient.ui.satisfaction.ui.view.ITemplateView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2019/4/18 0018.
 */

public class TemplatePresenter implements ITemplatePresenter{
    private ISatisfactionModel model;
    private ITemplateView view;

    public TemplatePresenter(ISatisfactionModel model, ITemplateView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void inquireSatisfactionTemplateTypeList(Map<String, String> praise) {
        model.inquireSatisfactionTemplateTypeList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<TemplateTypeBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast(e.getMessage());
                    }

                    @Override
                    public void onNext(BaseEntity<TemplateTypeBean> bean) {
                        view.inquireSatisfactionTemplateTypeList(bean);
                    }
                });
    }

    @Override
    public void inquireSatisfactionTemplateList(Map<String, String> praise) {
        model.inquireSatisfactionTemplateList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<TemplateBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast(e.getMessage());
                    }

                    @Override
                    public void onNext(BaseEntity<TemplateBean> bean) {
                        view.inquireSatisfactionTemplateList(bean);
                    }
                });
    }
}
